﻿using Common.AspNetCore;
using Common.Infrastructure;
using FCP.Api.Models;
using FCP.Api.Service;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace FCP.Api.Controllers
{
    [Route("api/FCPConfig")]
    public class FCPConfigController : ApiController
    {
        private readonly FCPConfigService fpcService; 
        public FCPConfigController(IServiceProvider provider, FCPConfigService auth)
             : base(provider)
        {
            this.fpcService = auth; 
        }
        [HttpPost, Route("GetTableConfig")]
        public async Task<ApiActionResult<FCPTableConfigModel>> GetTableConfig([FromBody] ApiParam  apiParam)
        {
            return await SafeExecuteAsync<FCPTableConfigModel>(async (param) =>
            { 
                return await this.fpcService.GetTableConfigAsync(apiParam); ;
            });
        }

        [HttpPost, Route("GetEditConfig")]
        public async Task<ApiActionResult<FCPEditConfigModel>> GetEditConfig([FromBody] ApiParam apiParam)
        {
            return await SafeExecuteAsync<FCPEditConfigModel>(async (param) =>
            {
                return await this.fpcService.GetEditConfigAsync(apiParam); ;
            });
        }

        [HttpPost, Route("GetSearchConfig")]
        public async Task<ApiActionResult<FCPSearchConfigModel>> GetSearchConfig([FromBody] ApiParam apiParam)
        {
            return await SafeExecuteAsync<FCPSearchConfigModel>(async (param) =>
            {
                return await this.fpcService.GetSearchConfigAsync(apiParam); ;
            });
        }

        [HttpPost, Route("GetTreeConfig")]
        public async Task<ApiActionResult<FCPTreeConfigModel>> GetTreeConfig([FromBody] ApiParam apiParam)
        {
            return await SafeExecuteAsync<FCPTreeConfigModel>(async (param) =>
            {
                return await this.fpcService.GetTreeConfigAsync(apiParam); ;
            });
        }
    }
}
